// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Boss Barrier Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 65 : TYPE_BOSSBARRIER


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 1
		object.frame = object.animationTimer
		object.frame >>= 2
		object.animationTimer++
		object.animationTimer %= 12
		object.value0++
		if object.value0 == 64
			object.state = 3
		end if
		object.value1 = object.value0
		object.value1 *= -0x8000
		object.value1 += object.ypos
		object.value2 = object.value0
		object.value2 *= -0x10000
		object.value2 += object.ypos
		object.value3 = object.value0
		object.value3 *= -0x18000
		object.value3 += object.ypos
		object.value4 = object.value0
		object.value4 *= -0x20000
		object.value4 += object.ypos
		object.value5 = object.value0
		object.value5 *= -0x28000
		object.value5 += object.ypos
		object.value6 = object.value0
		object.value6 *= -0x30000
		object.value6 += object.ypos
		object.value7 = object.value0
		object.value7 *= -0x38000
		object.value7 += object.ypos
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -16, -320, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 2
		object.frame = object.animationTimer
		object.frame >>= 2
		object.frame += 3
		object.animationTimer++
		object.animationTimer %= 12
		object.value0--
		if object.value0 == 0
			object.state = 0
		end if
		object.value1 = object.value0
		object.value1 *= -0x4000
		object.value1 += object.ypos
		object.value2 = object.value0
		object.value2 *= -0x8000
		object.value2 += object.ypos
		object.value3 = object.value0
		object.value3 *= -0xC000
		object.value3 += object.ypos
		object.value4 = object.value0
		object.value4 *= -0x10000
		object.value4 += object.ypos
		object.value5 = object.value0
		object.value5 *= -0x14000
		object.value5 += object.ypos
		object.value6 = object.value0
		object.value6 *= -0x18000
		object.value6 += object.ypos
		object.value7 = object.value0
		object.value7 *= -0x1C000
		object.value7 += object.ypos
		temp0 = object.value0
		temp0 *= -192
		temp0 >>= 7
		temp0 -= 18
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -16, temp0, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].ypos += 0x20000
			end if
		next
		break
	case 3
		object.value0 = 128
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -16, -320, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	end switch
end event


event ObjectDraw
	switch object.state
	case 0
		DrawSprite(0)
		break
	case 1
	case 2
	case 3
		DrawSpriteXY(6, object.xpos, object.value7)
		DrawSpriteXY(6, object.xpos, object.value6)
		DrawSpriteXY(6, object.xpos, object.value5)
		DrawSpriteXY(6, object.xpos, object.value4)
		DrawSpriteXY(6, object.xpos, object.value3)
		DrawSpriteXY(6, object.xpos, object.value2)
		DrawSpriteXY(6, object.xpos, object.value1)
		DrawSprite(object.frame)
		break
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 110, 223)
	SpriteFrame(-16, -16, 32, 32, 176, 223)
	SpriteFrame(-16, -16, 32, 32, 209, 223)
	SpriteFrame(-16, -16, 32, 32, 209, 223)
	SpriteFrame(-16, -16, 32, 32, 176, 223)
	SpriteFrame(-16, -16, 32, 32, 110, 223)
	SpriteFrame(-16, -16, 32, 32, 110, 190)
	if screen.xsize == 320
		foreach (TypeName[Boss Barrier], arrayPos0, ALL_ENTITIES)
			object[arrayPos0].type = TypeName[Boss Block]
		next
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
